package me.ingxin.android.drawable

import android.text.SpannableString
import android.text.Spanned


/**
 * 将TextDrawable转化成SpannableString，然后append到SpannableStringBuilder后直接使用
 * ```
 *      val sb = SpannableStringBuilder()
 *      sb.append(textDrawable.toSpannableString())
 *      sb.append("hell world")
 * ```
 */
fun TextDrawable.toSpannableString(marginStart: Int = 0, marginEnd: Int = 0): SpannableString {
    //设置drawable大小布局界限
    setBounds(0, 0, intrinsicWidth, intrinsicHeight)
    val span = CenterImageSpan(this, marginStart, marginEnd)
    val ss = SpannableString(getContent() ?: "")
    ss.setSpan(span, 0, ss.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
    return ss
}